<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="../vue.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      姓：<input type="text" v-model="firstName" /> <br />
      名：<input type="text" v-model="lastName" /> <br />
      全名: <span>{{fullName}}</span>
    </div>
    <script>
      var app = new Vue({
        el: "#app",
        data: {
          firstName: "老",
          lastName: "六",
          fullName: "老-六",
        },
        computed: {
          //computed 不支持异步
          demo() {
            return setTimeout(() => {
              return this.firstName + "-" + this.lastName;
            }, 1000);
          },
        },
        //监视？监视谁？
        //姓和名都要监视
        //只要有变动，我们的全名就得更改
        //怎么简单怎么来
        //当你简写能实现的时候就简写，当你发现没有立即监视没有deep完成不了这个需求的时候，自然就会写完整写法
        watch: {
          //姓
          firstName(newValue) {
            setTimeout(() => {
              this.fullName = newValue + "-" + this.lastName;
            }, 1000);
          },
          //名
          lastName(newValue) {
            this.fullName = this.firstName + "-" + newValue;
          },
        },
      });
    </script>
  </body>
</html>
